package co.gov.medellin.ssti.sub.service;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;

import javax.naming.NamingException;

import co.gov.medellin.ssti.sub.common.ConexionFactory;
import co.gov.medellin.ssti.sub.model.dao.DAOFactory;
import co.gov.medellin.ssti.sub.model.dao.IReporteTotalBeneficiariosDAO;
import co.gov.medellin.ssti.sub.model.dao.exception.DAOException;
import co.gov.medellin.ssti.sub.model.vo.RepDetBeneficiarioVO;
import co.gov.medellin.ssti.sub.model.vo.ReporteTotalBeneficiosOtorVO;

public class ReporteTotalBeneficiariosService {
	/**
	 * 
	 * @param criteria
	 * @return
	 * @throws DAOException
	 */
	public Collection<ReporteTotalBeneficiosOtorVO> findBeneficiarios(
			RepDetBeneficiarioVO criteria) throws DAOException {
		IReporteTotalBeneficiariosDAO reporteTotalBeneficiariosDAO = null;
		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			reporteTotalBeneficiariosDAO = DAOFactory.getDAOFactory(
					DAOFactory.ORACLE).getReporteTotalBeneficiariosDAO(con);
			return reporteTotalBeneficiariosDAO.findBeneficiarios(criteria);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (reporteTotalBeneficiariosDAO != null) {
				if (!reporteTotalBeneficiariosDAO.isConnClosed()) {
					reporteTotalBeneficiariosDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param repDetBeneficiarioVO
	 * @return
	 * @throws DAOException
	 */
	public RepDetBeneficiarioVO findFilters(
			RepDetBeneficiarioVO repDetBeneficiarioVO) throws DAOException {
		IReporteTotalBeneficiariosDAO reporteTotalBeneficiariosDAO = null;
		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			reporteTotalBeneficiariosDAO = DAOFactory.getDAOFactory(
					DAOFactory.ORACLE).getReporteTotalBeneficiariosDAO(con);
			return reporteTotalBeneficiariosDAO
					.findFilters(repDetBeneficiarioVO);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (reporteTotalBeneficiariosDAO != null) {
				if (!reporteTotalBeneficiariosDAO.isConnClosed()) {
					reporteTotalBeneficiariosDAO.close();
				}
			}
		}
	}
}
